/**
 * Copyright (C)  2011  chen wei hua.
 * Permission is granted to copy, distribute and/or modify this document
 * under the terms of the GNU Free Documentation License, Version 2.0
 * or any later version published by the Free Software Foundation;
 * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
 * A copy of the license is included in the section entitled "GNU Free Documentation License".
 */
package com.javaeye.store.service;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.javaeye.store.dao.MaterialsBatchDetailDAO;
import com.javaeye.store.dto.MaterialsBatchDetail;

public class MaterialsBatchInfoService implements IMaterialsBatchInfoService {
	
	private static Log log = LogFactory.getLog(MaterialsBatchInfoService.class);
	
	private MaterialsBatchDetailDAO dao;
	
	public void setDao(MaterialsBatchDetailDAO dao) {
		this.dao = dao;
	}

	public List<MaterialsBatchDetail> getBatchInfoByMaterialsId(int materialsId) {
		List<MaterialsBatchDetail> results = dao.getBatchInfoByMaterialsId(materialsId);
		if (results == null || results.size() == 0) {
			log.warn("在数据库中未找到待理货的物料批次信息, id=" + materialsId);
		}
		return results;
	}
	
	public List<MaterialsBatchDetail> getNotFinishBatchInfo(int materialsId) {
		List<MaterialsBatchDetail> results = dao.getNotFinishBatchInfo(materialsId);
		if (results == null || results.size() == 0) {
			log.warn("在数据库中未找到待生产的物料批次信息, id=" + materialsId);
		}
		return results;
	}
	
	/**
	 * 返回没有完成的产品计划批号
	 * @return
	 */
	public List<String> getNotFinishProductBatchInfo() {
		List<String> results = dao.getNotFinishProductBatchInfo();
		return results;
	}
	
	public MaterialsBatchDetail getBatchInfo(int batchDetailId) {
		MaterialsBatchDetail result = dao.getBatchInfo(batchDetailId);
		if (result == null) {
			log.warn("在数据库中未找到物料批次信息");
		}
		return result;
	}
	
	public MaterialsBatchDetail getBatchInfo(int materialsId, String batchNo) {
		MaterialsBatchDetail result = dao.getBatchDetail(materialsId, batchNo);
		if (result == null) {
			log.warn("在数据库中未找到物料批次信息");
		}
		return result;
	}
	
	public List<MaterialsBatchDetail> getNotEmptyMeterialsBatchInfo(int materialsId) {
		List<MaterialsBatchDetail> results = dao.getNotEmptyMeterialsBatchInfo(materialsId);
		if (results == null || results.size() == 0) {
			log.warn("在数据库中未找到未领用完的物料批次信息, id=" + materialsId);
		}
		return results;
	}
	
	/**
	 * 查询有退货，且未退完的物料的最大采购价格
	 * @param materialsId
	 * @return
	 */
	public double getMaxPrice(int materialsId) {
		return dao.getMaxPrice(materialsId);
	}
	
	/**
	 * 查询有退货物料的批次信息
	 * @param materialsId
	 * @return
	 */
	public List<MaterialsBatchDetail> getDefectiveMaterialsBatchInfo(int materialsId) {
		List<MaterialsBatchDetail> results = dao.getDefectiveMaterialsBatchInfo(materialsId);
		if (results == null || results.size() == 0) {
			log.warn("在数据库中未找到有退货物料的批次信息, id=" + materialsId);
		}
		return results;
	}
	
}
